package models

import (
	"3rd/mongo"
	"3rd/utils/push"
	"github.com/astaxie/beego/logs"
	"github.com/revel/revel"
	"time"
	"os"
)

var (
	db_contract  = "contract"
	col_contract = "contract"

	//db_demander  = "demander"
	//col_demander = "demander"

	db_device  = "device"
	col_device = "device"

	db_order  = "order"
	col_order = "order"

	db_postman  = "postman"
	col_postman = "postman"

	db_provider  = "provider"
	col_provider = "provider"

	db_station  = "station"
	col_station = "station"

	db_feedback  = "feedback"
	col_feedback = "feedback"

	Log *logs.BeeLogger

	HbInterval int
	timers     map[string]*time.Timer
	
	appKey string
	secret string
	appKey_postman string
	secret_postman string
)

func Init() {
	mongoConn := revel.Config.StringDefault("mongo", "root:123456@localhost:27017")
	mongo.InitMongo(mongoConn)

	uc = revel.Config.StringDefault("uc", "192.168.0.100:9000")

	push.InitJpush(revel.Config.StringDefault("jpush.appKey", "b8a86fc270ad92e417145a22"),
		revel.Config.StringDefault("jpush.secret", "d47ff90663c95614e1197962"))

	timers = make(map[string]*time.Timer)

	Log = logs.NewLogger(10000)
	Log.SetLogger("console", "")
	Log.EnableFuncCallDepth(true)
//	dir := filepath.Dir(os.Args[0])
//	dir, _ = filepath.Abs(dir)
//	path := filepath.Join(dir, "waterblabla.log")    
//	path = strings.Replace(path, `\`, "/", -1)
//	Log.Debug(path)
// TODO: hack
	os.MkdirAll("c:/logs/waterblabla", os.ModeDir)
	Log.SetLogger("file", `{"filename":"` + "c:/logs/waterblabla/waterblabla.log" +`"}`)
	Log.SetLogger("smtp", revel.Config.StringDefault("beelog.smtp", ""))

	HbInterval = revel.Config.IntDefault("dev.hbInterval", 60)
	
	appKey = revel.Config.StringDefault("jpush.appKey", "b8a86fc270ad92e417145a22")
	secret = revel.Config.StringDefault("jpush.secret", "d47ff90663c95614e1197962")
	appKey_postman = revel.Config.StringDefault("jpush.appKey_postman", "b8a86fc270ad92e417145a22")
	secret_postman = revel.Config.StringDefault("jpush.secret_postman", "d47ff90663c95614e1197962")
}
